//
//  CZMainViewController.swift
//  iOS9GZweibo
//
//  Created by 王应明 on 16/3/22.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //自定义tabBar
        self.setValue(CZMainTabBar(), forKey: "tabBar")
        
        addChildViewControllers()
        
    }
    
    func addChildViewControllers(){
        
        //首页
        let homeVC = CZHomeViewController()
        addChildViewController(homeVC, title: "首页", imageName: "tabbar_home")
        
        //消息
        let messageVC = CZMessageViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        //发现
        let discoverVC = CZDiscoverViewController()
        addChildViewController(discoverVC, title: "发现", imageName: "tabbar_discover")
        
        //我
        let profileVC = CZProfileViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
        
    }
    
    ///添加为tabBar子控制器
    func addChildViewController(controller: UIViewController, title: String, imageName: String) {
        
        //设置标题
        controller.title = title
        
        //设置普通图片
        controller.tabBarItem.image = UIImage(named: imageName)
        
        //拼接图片
        let hightedImageName = imageName + "_highlighted"
        
        //设置高亮图片
        controller.tabBarItem.selectedImage = UIImage(named: hightedImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //设置字体颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        
        addChildViewController(UINavigationController(rootViewController: controller))
    }
}



   